package com.bawei.park2302.splashScreen

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_base.utils.utils.mvi.BaseViewActivity
import com.bawei.park2302.R
import com.bawei.park2302.databinding.ActivitySplashScreenBinding
import com.blankj.utilcode.util.SPUtils
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*

@AndroidEntryPoint
class SplashScreenActivity : BaseViewActivity<ActivitySplashScreenBinding>() {
    override val binding: ActivitySplashScreenBinding by lazy {
        ActivitySplashScreenBinding.inflate(layoutInflater)
    }

     var timer : Timer?=null
    var time = 6

    override fun initView() {
        timer = Timer()
        lifecycleScope.launch(Dispatchers.IO){
            timer!!.schedule(object : TimerTask(){
                override fun run() {
                    time--
                    lifecycleScope.launch(Dispatchers.IO){
                        binding.shapeCountdown.text = "${time}S"
                    }
                    if (time == 0){
                        timer!!.cancel()
                        ARouter.getInstance().build("/app/LoginActivity").navigation()
                        finish()
                    }
                }
            },0,1000)
        }

        binding.shapeSkip.setOnClickListener {
            ARouter.getInstance().build("/app/LoginActivity").navigation()
            timer?.cancel()
            finish()
        }
    }

    override fun initData() {

    }

    override fun onDestroy() {
        super.onDestroy()
        if (timer != null){
            timer?.cancel()
            timer == null
        }
    }
}